*** Settings ***
Resource   ../Common_Head.robot

*** Variables ***
&{PROJECT_PARAM}    TENDER_ID=    TENDER_TITLE=    CUSTOEMR_NAME=    CUSTOMER_LEVEL=
          ...   MODE=    DEADLINE_TM_DATE=    VALID_FROM=DEFAULT    VALID_TO=DEFAULT
          ...    DEPUTY=    TEMPLATE=    DEADLINE_TM_TIME=DEFAULT    DEADLINE_TM_MINITE=DEFAULT

*** Keywords ***
Create Project
    [Arguments]    ${project_param}
    #1.User clicks "Create Project" button.
    Wait Until Keyword Succeeds    5x    100ms    Click   ${navigation_pricing_project}
    Wait For Elements State    ${Project_toolbar_CreateButton}    visible    10
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    100ms    Click    ${Project_toolbar_CreateButton}
    Wait For Elements State   ${Project_create_TenderID}     enabled
    #2.User inputs 'R2018' in the Tender ID field
    Fill Text    ${Project_create_TenderID}    ${project_param.TENDER_ID}
    Sleep    1
    Wait For Elements State    ${Project_create_TenderIdDropDown}    visible    60
    Wait Until Search Finished
    #3.User chooses the "R2018(Regress)" from the dropdown list.  
    Click    ${Project_create_TenderIdDropDown}
    Wait Until Keyword Succeeds    5x    200ms    Check Text Value    ${Project_create_ProjectName}    ${project_param.TENDER_ID}-undefined-${project_param.TENDER_TITLE}
    Check Text Value    ${Project_create_Customer}    ${project_param.CUSTOEMR_NAME}
    Check Text Value    ${Project_create_Level}    ${project_param.CUSTOMER_LEVEL}
    #4.User clicks dropdown list from Mode field.
    Get Select Options    select[id='mode']    validate    [v["label"] for v in value] == ["--please select a mode--","AIR", "FCL", "LCL"]
    #5.User chooses LCL from the dropdown list.
    Select Options By   ${Project_create_Mode}    label    ${project_param.MODE}
    Check Text Value    ${Project_create_ProjectName}    ${project_param.TENDER_ID}-${project_param.MODE}-${project_param.TENDER_TITLE}
    # #6.User selects the '2022-09-12' for Deadline to TM field. comment step6
    Fill Text    ${Project_create_DeadlinetoTMDate}    ${project_param.DEADLINE_TM_DATE}
    # Press Keys   ${Project_create_DeadlinetoTMDate}    ${project_param.DEADLINE_TM_DATE}
    # # Fill Text    ${Project_create_DeadlinetoTMDate}    ${project_param.DEADLINE_TM_DATE}
    # ## if press key or input key to date field, this date field will be filled with 2020 for year part
    # Repeat Keyword    2     Press Keys   ${Project_create_DeadlinetoTMDate}    DELETE
    # Check Text Value    ${Project_create_DeadlinetoTMDate}    ${project_param.DEADLINE_TM_DATE}
    IF    '${project_param.DEADLINE_TM_TIME}'!='DEFAULT'
        Select Options By    ${Project_create_DeadlinetoTMHour}    label    ${project_param.DEADLINE_TM_TIME}
    END
    IF    '${project_param.DEADLINE_TM_MINITE}'!='DEFAULT'
        Select Options By    ${Project_create_DeadlinetoTMMinute}    label    ${project_param.DEADLINE_TM_MINITE}
    END
    #7.User selects the '2022-09-12' for Rate Validity From;
    #User selects the '2022-10-01' for Rate Validity To;
    IF    '${project_param.VALID_FROM}'=='DEFAULT'
           ${CurDate}    Get Current Date    result_format=%d/%m/%Y
           ${FutureDate}    Get Current Date    UTC    +30days    result_format=%d/%m/%Y
           Set To Dictionary    ${project_param}    VALID_FROM=${CurDate}    VALID_TO=${FutureDate}
    END
    Fill Text    ${Project_create_RateValidityFrom}    ${project_param.VALID_FROM}
    Fill Text    ${Project_create_RateValidityTo}   ${project_param.VALID_TO}
    #8.User clicks Deputy button.
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_create_Deputies}
    #9.User inputs SNOWLI01 in the SIMS ID field, clicks search button.
    Wait For Elements State   Select[data-ng-change="selectedCriterion(qe.id, 'simsId')"]     enabled    30
    Fill Text     css = [data-type-validation='Joose.Type.Str']    ${project_param.DEPUTY}
    Click    ${user_locator_search_button} 
    Wait For Elements State    xpath=//td[.='${project_param.DEPUTY}']    visible    
    #10.User clicks select button.
    Click    xpath=//td[.='${project_param.DEPUTY}']
    Click    ${user_locator_selectButton} 
    Wait Until Search Finished
    IF    r'${project_param.TEMPLATE}'!=''
        #11.User clicks upload button in Attached Documents section.
        # Mouse Move Relative To     ${Project_create_UploadButton}    0.0    200
        Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_create_UploadButton}
        Wait For Elements State   ${upload_addFileButton}     enabled
        #12.User clicks Add file button, chose one file from the local computer
        Upload File By Selector    ${upload_addFileButton}    ${project_param.TEMPLATE}
    END
    #13.User checks the information at the bottom of this dialog.
    Wait For Elements State    ${Project_create_ProjectOwner}    visible    
    Check Text Value    ${Project_create_ProjectOwner}    ${USERNAME_FULL}
    ${CurrentDate}    Get Current Date      result_format=%d/%m/%Y
    Check Text Value    ${Project_create_CreateDate}    ${CurrentDate}
    Check Text Value    ${Project_create_Status}    In Progress
    # Mouse Move Relative To     ${Project_create_UploadButton}    0.0    200
    #14.User clicks save button.
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_create_SaveButton}
    Wait Until Search Finished

Search Project
    [Arguments]    ${TENDER_ID}
    # ${project_name}   Set Variable    ${TENDER_ID}-${MODE}-${TENDER_TITLE}
    Wait Until Search Finished
    Select Options By   ${project_search_criteria}    label    Tender ID
    Select Options By   ${project_search_operator}    label    Equals
    Fill Text    ${project_search_operand}    ${TENDER_ID}
    Click    ${project_search_searchButton}
    Wait Until Search Finished
    # Mouse Move Relative To    xpath = //td[.='${project_name}']    0.0    200
    Click    xpath = //td[contains(text(),'${TENDER_ID}')]

Delete Project
    [Arguments]    ${TENDER_ID}
    Wait Until Search Finished
    ${status}    Run Keyword And Return Status    Get Element States    ${navigation_pricing_project}    contains    visible
    IF    "${status}" != "True"
        Click    ${navigation_pricing_collaboration}
    END
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    100ms    Click   ${navigation_pricing_project}
    Wait For Elements State    ${Project_toolbar_CreateButton}    visible    10
    Search Project    ${TENDER_ID}
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_toolbar_DeleteButton}
    Mouse Move Relative To    ${project_delete_yesButton}    0.0    200
    Wait For Elements State    ${project_delete_yesButton}    visible    60
    Click    ${project_delete_yesButton}
    Wait Until Search Finished

Template Management
    [Arguments]    ${project_param}    ${TemplateFile}
    # 1 User goes to Pricing Collaboration , Pricing Project.
    Wait Until Keyword Succeeds    5x    300ms    Click   ${navigation_pricing_project}
    Wait For Elements State    ${Project_toolbar_CreateButton}    visible    10
    Wait Until Search Finished
    # 2 User select the row which project name
    Search Project    ${project_param.TENDER_ID}    ${project_param.MODE}    ${project_param.TENDER_TITLE}
    # 3 User clicks template management button check
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_toolbar_TemplateManagementButton}
    Wait For Elements State    ${Template_Step1DownloadButton}    visible    
    Get Element States    ${Template_Step1DownloadButton}    not contains    disabled
    Wait For Elements State    ${Template_Dialogtitle}    visible    
    Check Text Value    ${Template_Dialogtitle}    ${project_param.TENDER_ID}-${project_param.MODE}-${project_param.TENDER_TITLE}
    Check Text Value    ${Template_Step2title}    Step2: Select and Define Optional Columns
    Check Text Value    ${Template_Step3title}    Step3: Generate Internal Pricing Template
    Check Text Value    ${Template_Step3DownloadFlag}    on
    Wait Until Search Finished
    # 4 User clicks download button.
    ${filename}    Download File    ${Template_Step1DownloadButton}
    # ${filename}    Get Download File Name    ${project_param.TENDER_ID}-${project_param.MODE}-${project_param.TENDER_TITLE}_DC    zip
    # 5 Select Column 
    # IF    '${project_param.MODE}' == 'AIR'
    #     Select Column for AIR Template
    # END
    # IF    '${project_param.MODE}' == 'FCL'
    #     Select Column for FCL Template
    # END
    # IF    '${project_param.MODE}' == 'LCL'
    #     Select Column for LCL Template
    # END
    Check All Check Box for Dialog    Step2: Select and Define Optional Columns
    Uncheck ALL TBN Checkbox    Step2: Select and Define Optional Columns
    # 6 User clicks start button.
    Wait Until Search Finished
    ${filename}    Download File    ${Template_StartButton}
    Wait Until Search Finished
    Wait Until Search Finished
    # Wait Until Keyword Succeeds   200    1    Get Element States    ${Template_StartButton}    not contains    visible
    # Wait Until Keyword Succeeds   20x    500ms    Get Element States    ${Template_UploadButton}    contains    visible
    # Wait Until Keyword Succeeds   20x    500ms    Get Element States    ${Template_DownloadGeneratedTemplateButton}    contains    visible
    # Wait Until Search Finished
    # Wait Until Search Finished
    Wait Until Keyword Succeeds    20x    400ms    Get Page Source    contains        Successful
    Check Text Value    ${Template_Summary}    Successful
    # ${filename}    Get Download File Name    ${project_param.TENDER_ID}-${project_param.MODE}-${project_param.TENDER_TITLE}_
    # 7 User clicks upload button
    Click    ${Template_UploadButton}
    Wait For Elements State   ${upload_addFileButton}     enabled
    # 8 User select the modified file
    Upload File By Selector    ${upload_addFileButton}    ${TemplateFile}
    Wait Until Search Finished
    Wait Until Search Finished
    Wait Until Keyword Succeeds    20x    400ms    Get Page Source    contains        Successful
    Check Text Value    ${Template_Summary}    Successful
    Wait Until Search Finished
    # 9 User clicks download file.
    Wait Until Keyword Succeeds   200    1    Get Element States    ${upload_addFileButton}    not contains    visible
    Wait Until Keyword Succeeds   20x    500ms    Get Element States   ${Template_DownloadGeneratedTemplateButton}    contains    visible
    Wait Until Keyword Succeeds   20x    500ms    Get Element States   ${Template_DownloadGeneratedTemplateButton}    not contains    disabled
    Wait Until Search Finished
    Wait Until Search Finished
    Wait Until Keyword Succeeds   200    1    Click    ${Template_DownloadGeneratedTemplateButton}
    Wait Until Search Finished
    # 10 User clicks skip button (for AIR)
    # IF    '${project_param.MODE}' == 'AIR'
    Push Skip and check for AIR Template
    # END
    # 11 There is a button named Next: Round Management appeared
    Wait Until Search Finished
    Wait For Elements State    ${Template_NextRoundManagementButton}    enabled
    # Wait Until Keyword Succeeds   20x    500ms    Get Element State    ${Template_gotoNextButton}    visible    should be    True
    # 12 User clicks close button
    Click    ${Template_CloseButton}
    Wait Until Search Finished

Routing Confirmation
    [Documentation]    assign project to specified user, modify/check modified setup file
    [Arguments]    ${setupModifyColumn}=2
    Remove All Files
    Close All Excel Documents
    #1.search project
    Search Project    ${PROJECT.TENDER_ID}
    Wait Until Search Finished
    #2.User clicks round management button.
    Click    ${Project_toolbar_RoundMgmtButton}
    Wait For Elements State    ${Project_RoundMgmt_CurrentRole}    enabled    60
    #3. User clicks routing confirmation button.The confirm button is gray.
    #   The status of the region is not reviewed.
    Wait For Elements State    ${Project_RoundMgmt_RoutConfirmButton}    enabled    30
    Click    ${Project_RoundMgmt_RoutConfirmButton}
    Wait For Elements State    ${Project_RoundMgmt_Routing_Confirm}    visible    60
    Get Element States    ${Project_RoundMgmt_Routing_Confirm}    disabled    ==    True
    #4.User clicks APAC to check ,the others uncheck and clicks download.
    #Open the file and it has two lanes.
    Click    xpath=//div//tr[td//text()[contains(.,"APAC")]]//input[@type='checkbox']
    ${filename}    Download File    ${Project_RoundMgmt_Routing_Download}
    # ${filename}    Get Download File Name    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}_Round 1
    Wait Until Keyword Succeeds    3x    500ms    Open Excel Document     ${filename}    ${PROJECT.MODE}
    ${landInfo}    Read Excel Column    1
    ${rowCount}    Get Length    ${landInfo}
    Should Be Equal As Integers    ${rowCount}    3   ##there are three rows incldued column title
    Close Current Excel Document
    Remove File    ${filename}
    #5.User clicks NAM to check ,the others uncheck and clicks download.
    #Open the file and it has only one lane
    Click    xpath=//div//tr[td//text()[contains(.,"APAC")]]//input[@type='checkbox']
    Click    xpath=//div//tr[td//text()[contains(.,"NAM")]]//input[@type='checkbox']
    ${filename}    Download File    ${Project_RoundMgmt_Routing_Download}
    # ${filename}    Get Download File Name    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}_Round 1*
    Open Excel Document     ${filename}    ${PROJECT.MODE}
    ${landInfo}    Read Excel Column    1    
    ${rowCount}    Get Length    ${landInfo}
    Should Be Equal As Integers    ${rowCount}    2   ##there are three rows incldued column title
    Close Current Excel Document    
    Remove File    ${filename}
    #6.User clicks Europe to check ,the others uncheck and clicks download.
    #Open the file and it has only one lane   
    Click    xpath=//div//tr[td//text()[contains(.,"NAM")]]//input[@type='checkbox']
    Click    xpath=//div//tr[td//text()[contains(.,"EUROPE")]]//input[@type='checkbox']
    ${filename}    Download File    ${Project_RoundMgmt_Routing_Download}
    # ${filename}    Get Download File Name    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}_Round 1
    Open Excel Document     ${filename}    ${PROJECT.MODE}
    ${landInfo}    Read Excel Column    1       
    ${rowCount}    Get Length    ${landInfo}
    Should Be Equal As Integers    ${rowCount}    2   ##there are two rows incldued column title
    Close Current Excel Document    
    Remove File    ${filename}
    #8.Click Setup
    Click    ${Project_RoundMgmt_Routing_Setup}
    Wait For Elements State    ${Project_RoundMgmt_Setup_Download}    visible    10
    #9.Download
    ${filename}    Download File    ${Project_RoundMgmt_Setup_Download}
    # ${filename}    Get Download File Name    RoutingSetupFile
    Sleep    2
    #10.check download file column
    Open Excel Document     ${filename}    Sheet0
    ${titleList}    Read Excel Row    1
    Lists Should Be Equal    ${titleList}    ${ROUTING_FILE_COLUMN}    ignore_order=True
    ${laneInfo}    Read Excel Column    1       
    ${rowCount}    Get Length    ${laneInfo}
    Should Be Equal As Integers    ${rowCount}    3   ##there are three rows incldued column title
    Close Current Excel Document
    Open Excel Document     ${filename}    Sheet0
    #11.modify file
    Write Excel Cell    2    ${setupModifyColumn}    Not Allowed    Sheet0
    Write Excel Cell    3    ${setupModifyColumn}    Not Allowed    Sheet0
    Save Excel Document    ${filename}
    Close Current Excel Document
    Sleep    2
    #12.upload modified file
    Click    ${Project_RoundMgmt_Setup_Upload}
    Wait For Elements State    ${Project_RoundMgmt_Setup_UploadAddFile}    visible    60
    #13.Click OK
    Wait For Elements State   ${Project_RoundMgmt_Setup_UploadAddFile}     enabled
    Upload File By Selector    ${upload_addFileButton}    ${filename}
    Wait Until Search Finished
    Wait For Elements State    ${Project_RoundMgmt_Setup_UploadAddFile_OKButton}    visible    60
    Click    ${Project_RoundMgmt_Setup_UploadAddFile_OKButton}
    Remove File    ${filename}
    Sleep    2
    #14.download file
    Click    ${Project_RoundMgmt_Routing_Setup}
    ${filename}    Download File    ${Project_RoundMgmt_Setup_Download}
    # ${filename}    Get Download File Name    RoutingSetupFile
    #15.check download file
    Open Excel Document     ${filename}    Sheet0
    Check Cell Value    2    ${setupModifyColumn}    Not Allowed    Sheet0
    Check Cell Value    3    ${setupModifyColumn}    Not Allowed    Sheet0   
    Close All Excel Documents
    Remove File     ${filename}
    Click    ${Dialog_Close}
    Click    ${Dialog_Close}
    Sleep    1
    Click    ${Project_RoundMgmt_Routing_Close}
    #16.assign
    Wait Until Keyword Succeeds    5x    100ms    Click    ${Project_RoundMgmt_AssignButton}
    Wait For Elements State    ${Project_RoundMgmt_Assign_ApacTab}    visible    
    Click    xpath= //div[@data-model='selectedItems']
    Round Mgmt Assign User    ${Project_RoundMgmt_Assign_ApacTab}    xpath= //div[@data-model='availableItems']//ul//li//b[.='Mary Ma (MARYMA01)']
    Round Mgmt Assign User    ${Project_RoundMgmt_Assign_EuropeTab}    xpath= //div[@class='tab-pane ng-scope active']//div[@class='tab-pane ng-scope active']//b[.='Kiki Xia (KIKIXIA1)']
    Round Mgmt Assign User    ${Project_RoundMgmt_Assign_NamTab}    xpath = //b[.='Snow Li (SNOWLI01)']
    Click    ${Project_RoundMgmt_Assign_SaveButton}
    Wait Until Search Finished
    Click    ${Project_RoundMgmt_StartButton}
    Wait Until Keyword Succeeds    10x    100ms    Click    ${Project_RoundMgmt_StartConfirmButton} 
    Wait Until Search Finished
    Wait Until Keyword Succeeds    20x    100ms    Click    ${Project_RoundMgmt_Confirm_SendButton}
    Wait Until Search Finished
    Close Browser

Round Review
    [Arguments]    ${user}
    ##user login space
    Remove All Files
    Close All Excel Documents
    Set Global Variable    ${USERNAME}    ${user}
    Login Space
    ###search project
    Search Project    ${PROJECT.TENDER_ID}
    Wait Until Search Finished
    ###go to round managemnt-->rout confirmation-->download
    Wait Until Keyword Succeeds    10x    500ms    Click    ${Project_toolbar_RoundMgmtButton}
    Wait For Elements State    ${Project_RoundMgmt_CurrentRole}    enabled    60
    Wait Until Keyword Succeeds    10x    500ms    Select Options By   ${Project_RoundMgmt_CurrentRole}    label    ${REGIONAL_ROLE}
    Click    ${Project_RoundMgmt_RoutConfirmButton} 
    ${filename}    Download File    ${Project_RoundMgmt_Confirm_Download}
    Wait Until Search Finished
    ###modify download file then upload
    # ${filename}    Get Download File Name    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}_Round 1
    Copy File    ${filename}    ${filename}_COPY    
    Sleep    2    
    Open Excel Document     ${filename}    ${PROJECT.MODE}
    ${length}    Get Length    ${MODIFY_COLUMN_TITLE}
    FOR    ${index}    IN RANGE    0    ${length}
        ${columnIndex}    Get Excel Column Index    ${MODIFY_COLUMN_TITLE}[${index}]
        Write Excel Cell    2    ${columnIndex}    ${MODIFY_COLUMN_VALUE}[${index}]    ${PROJECT.MODE}
    END
    Sleep    2
    Save Excel Document    ${filename}
    Close Current Excel Document
    Click     ${Project_RoundMgmt_Confirm_Upload}
    Wait For Elements State    ${Project_RoundMgmt_Confirm_UploadAddFile}    visible    10
    Upload File By Selector    ${upload_addFileButton}    ${filename}
    Wait Until Search Finished
    Wait For Elements State    ${Project_RoundMgmt_Setup_UploadAddFile_OKButton}    visible    60
    Click    ${Project_RoundMgmt_Setup_UploadAddFile_OKButton}
    Remove File   ${filename}
    IF     '${PROJECT.MODE}'=='AIR'
        Copy File    ${filename}_COPY    ${filename}
        Click    ${Project_RoundMgmt_RoutConfirmButton} 
        Wait Until Keyword Succeeds    4x    500ms    Click     ${Project_RoundMgmt_Confirm_Upload}
        Wait For Elements State    ${Project_RoundMgmt_Confirm_UploadAddFile}    visible    5
        Upload File By Selector    ${upload_addFileButton}    ${filename}
        Wait For Elements State    ${Project_RoundMgmt_Setup_UploadAddFile_OKButton}    visible    60
        Sleep    2
        Click    ${Project_RoundMgmt_Setup_UploadAddFile_OKButton}
        Wait Until Search Finished
    END    
    Close Browser
    Remove File    ${filename}
    # ### user login as project owner
    Set Global Variable    ${USERNAME}    AUTOTEST
    Login Space
    Search Project    ${PROJECT.TENDER_ID}
    Wait Until Search Finished
    ### user go to round management-->routing confirmation to check region is reviewed
    Click    ${Project_toolbar_RoundMgmtButton}
    Wait For Elements State    ${Project_RoundMgmt_RoutConfirmButton}     enabled    60
    Click    ${Project_RoundMgmt_RoutConfirmButton}
    Wait For Elements State   ${Project_RoundMgmt_Routing_Download}    enabled    60
    Get Element States     xpath=//div//tr[td//text()[contains(.,"${REGION}")]][td//text()[contains(.,"Reviewed")]]    contains    visible
    Click    xpath=//div//tr[td//text()[contains(.,"${REGION}")]]//input[@type='checkbox']
    Click    ${Project_RoundMgmt_Routing_Confirm}
    Wait For Elements State    ${Project_RoundMgmt_Routing_Confirm_Approve}    enabled    30
    Click    ${Project_RoundMgmt_Routing_Confirm_Approve}
    Wait Until Search Finished
    Click    ${Dialog_Close}
     #Download IPT check the port information
    ${filename}    Download File    ${Project_RoundMgmt_DownloadButton}
    # ${filename}    Get Download File Name    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}_Round1_IPT
    Open Excel Document     ${filename}    ${PROJECT.MODE}_D
    FOR    ${index}    IN RANGE    0    ${length}
        ${columnIndex}    Get Excel Column Index    ${IPT_COLUMN_TITLE}[${index}]    4
        Check Cell Value    5    ${columnIndex}    ${IPT_COLUMN_VALUE}[${index}]    ${PROJECT.MODE}_D
    END
    Close Current Excel Document
    Click    ${Project_RoundMgmt_CloseButton} 

Round Mgmt Assign User
    [Arguments]    ${tab}    ${user}=default    ${tab2}=default value   
    Wait Until Keyword Succeeds    50    1    Click    ${tab}
    IF    "${tab2}"!="default value"
        Click    ${tab2}
    END
    Click if Enabled     ${Project_RoundMgmt_Assign_RemoveAll}
    IF    "${user}"!="default"
        Click    ${user}
        Click    ${Project_RoundMgmt_Assign_Add}
    END
    
Switch current user role
    [Arguments]    ${roleName}
    Wait For Elements State    //div[@ng-click="toggleDropdown()"]
    Click    //div[@ng-click="toggleDropdown()"]
    Click    //div[contains(text(),"${roleName}")]
Upload Lanes
    [Arguments]    ${uploadFile}
    # 1.User goes to Pricing Collaboration , Pricing Project
    Click   ${navigation_pricing_project}
    Wait For Elements State    ${Project_toolbar_CreateButton}    visible    10
    Wait Until Search Finished
    # 2.User select the row
    Search Project    ${PROJECT.TENDER_ID}
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    300ms    Get Element States    ${Project_toolbar_LaneManagementButton}    not contains    disabled
    # 3.User clicks Lane Management button.
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_toolbar_LaneManagementButton}
    Wait Until Search Finished
    Wait Until Keyword Succeeds    60    1    Get Element States    ${Project_LaneMgmt_UpdateRadio}    not contains    visible
    Get Element States    ${Project_LaneMgmt_DeleteRadio}        not contains    disabled 
    Get Element States    ${Project_LaneMgmt_AddRadio}        not contains    disabled 
    Get Element States    ${Project_LaneMgmt_NextButton}    not contains    disabled 
    Get Element States    ${Project_LaneMgmt_CloseButton}    not contains    disabled 
    Get Text    ${Project_LaneMgmt_UpdateInfo}    contains    Update Existing Lanes
    Get Text    ${Project_LaneMgmt_DeleteInfo}    contains    Delete Existing Lanes
    Get Text    ${Project_LaneMgmt_AddInfo}    contains    Add New Lanes
    # 4.User selects Update existing lanes.
    Click   ${Project_LaneMgmt_UpdateRadio}
    Wait Until Search Finished
    # 5.User clicks Next button.
    Wait Until Keyword Succeeds   20x    500ms    Click    ${Project_LaneMgmt_NextButton}
    Wait Until Search Finished
    Wait Until Keyword Succeeds    60    1    Get Element States    ${Project_LaneMgmt_UpdateLane_DownloadButton}    not contains    disabled
    Get Element States    ${Project_LaneMgmt_UpdateLane_UploadButton}       not contains    disabled
    Get Element States    ${Project_LaneMgmt_UpdateLane_BackButton}       not contains    disabled 
    Get Element States    ${Project_LaneMgmt_UpdateLane_CloseButton}    not contains    disabled 
    # 6.User clicks download button.
    ${filename}    Download File    ${Project_LaneMgmt_UpdateLane_DownloadButton}
    Wait Until Search Finished
    # ${filename}    Get Download File Name    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}_LMT
    # 7.User modifies the download file.
    Open Excel Document     ${filename}    ${PROJECT.MODE}
    Write Excel Cell    5    40    5.0    ${PROJECT.MODE}_D
    Save Excel Document    ${filename}
    Close Current Excel Document
    # 8.User clicks upload button.
    Wait Until Search Finished
    Click    ${Project_LaneMgmt_UpdateLane_UploadButton}
    Sleep    2
    # 9.User clicks add file button.
    ### uploaded prepared excel file to system, because scripts modified excel will cause error
    # Upload File By Selector    ${upload_addFileButton}    ${filename}
    Upload File By Selector    ${upload_addFileButton}    ${uploadFile}
    Wait Until Search Finished
    # 10.User selects modified file and upload it.
    Wait Until Keyword Succeeds    60    1    Get Element States    ${Project_LaneMgmt_MessageInfo}    contains    visible
    Get Text    ${Project_LaneMgmt_MessageInfo}    contains    Successfully uploaded
    # 11.User clicks close button.
    Click    ${Project_LaneMgmt_UpdateLane_CloseButton}
    # 12.User clicks lane management button again.
    Wait Until Search Finished
    Search Project    ${PROJECT.TENDER_ID}
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_toolbar_LaneManagementButton}
    Wait Until Search Finished
    Wait Until Keyword Succeeds    60    1    Get Element States    ${Project_LaneMgmt_UpdateRadio}    not contains    disabled
    # 13.User clicks next button.
    Wait Until Search Finished
    Wait Until Keyword Succeeds    60    1    Get Element States    ${Project_LaneMgmt_UpdateRadio}    not contains    disabled
    # 14.User clicks download button and check
    Wait Until Keyword Succeeds   20x    500ms    Click    ${Project_LaneMgmt_NextButton}
    Wait Until Search Finished
    Wait Until Keyword Succeeds    60    1    Get Element States    ${Project_LaneMgmt_UpdateLane_DownloadButton}    not contains    disabled
    ${filename}    Download File    ${Project_LaneMgmt_UpdateLane_DownloadButton}
    Wait Until Search Finished
    Open Excel Document     ${filename}    ${PROJECT.MODE}
    # ${value}=        Read Excel Cell    5    40    ${PROJECT.MODE}_D
    # Should Be Equal As Numbers    ${value}    5.0
    Close All Excel Documents
    Wait Until Search Finished
    Click    ${Project_LaneMgmt_UpdateLane_CloseButton}
    Wait Until Search Finished

Delete Lanes
    #     1). User goes to Pricing Collaboration , Pricing Project.
    Search Project    ${PROJECT.TENDER_ID}
    #     User select the row
    Wait For Elements State    ${Project_toolbar_LaneManagementButton}    enabled    20
    #     User clicks Lane Management button.
    Check A Dialog displays After Clicking Lane_Magm button    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}
    #     User selects Delete existing lanes.
    ${Status}    Run Keyword And Return Status    Get Checkbox State    ${Project_LaneMgmt_DeleteRadio}    ==    checked
    IF    '${Status}' == 'False'
        Click    ${Project_LaneMgmt_DeleteRadio}
    END
    #     User clicks Next button.
    Click If Enabled    ${Project_LaneMgmt_NextButton}
    #     User clicks upload button.
    Wait For Elements State    ${Project_LaneMgmt_DeleteLane_UploadButton}    enabled    90
    Click If Enabled    ${Project_LaneMgmt_DeleteLane_UploadButton}
    Wait Until Keyword Succeeds    10x    400ms    Get Page Source    contains    Upload Template
    #     User clicks download template link.
    Remove All Files
    ${filename}    Download File    ${Project_LaneMgmt_DeleteLane_DownloadTemplate}
    #     User modify the download document to add lane ID.
    # ${filename}    Get Download File Name    LaneIdDeleteTemplate
    Modify Excel File    ${filename}    2    1    REPORT    1
    #     User clicks add file button and upload the file.
    Upload File By Selector    ${Project_LaneMgmt_DeleteLane_AddFile}    ${filename}
    Wait Until Keyword Succeeds    10x    400ms    Get Page Source    contains    Are you sure that these 1 lanes need to be deleted? if so, please click confirm to continue.    50
    #     User clicks confirm button.
    Click    ${Project_LaneMgmt_DeleteLane_ConfirmButton}
    # Wait Until Keyword Succeeds    10x    400ms    Get Page Source    contains    1 lanes deleted successfully.    60
    Wait Until Keyword Succeeds    10x    400ms    Get Page Source    contains    lanes deleted successfully.    60
    #     User clicks close button.
    Wait For Elements State    ${Project_LaneMgmt_CloseButton}    enabled    30
    Click    ${Project_LaneMgmt_CloseButton}
    #     User clicks Lane Management button.
    Wait Until Keyword Succeeds    90    1    Click    xpath = //td[.='${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}']
    Check A Dialog displays After Clicking Lane_Magm button    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}
    #     User clicks update existing lanes.
    ${Status}    Run Keyword And Return Status    Get Checkbox State    ${Project_LaneMgmt_UpdateRadio}    ==    checked
    IF    '${Status}' == 'False'
        Click    ${Project_LaneMgmt_UpdateRadio}
    END
    #    User clicks next button.
    Click    ${Project_LaneMgmt_NextButton}
    #     User clicks download button.
    Wait For Elements State    ${Project_LaneMgmt_UpdateLane_DownloadButton}    visible    50
    Remove All Files
    ${filename}    Download File    ${Project_LaneMgmt_UpdateLane_DownloadButton}
    #     User open the download document.
    # ${filename}    Get Download File Name    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}
    Wait Until Keyword Succeeds    100    1    Open Excel Document    ${filename}    ${PROJECT.MODE}_D
    ${cellValue}    Read Excel Cell    4    7    ${PROJECT.MODE}_D
    Should Not Be Equal    ${cellValue}    1
    Close All Excel Documents
    Wait Until Keyword Succeeds    50    1    Click    ${Project_LaneMgmt_UpdateLane_CloseButton}

# Data Cleaning Project
#     [Documentation]    AIR: ROW=2 Col=27 Modify_Value=1  FCL: ROW=2 Col=29 Modify_Value=1  LCL: ROW=2 Col=26 Modify_Value=1
#     [Arguments]    ${Select_By}=Location
#     ${Modify_Value}    Set Variable    1
#     # 1.User goes to Pricing Collaboration , Pricing Project
#     # 2.User select the row
#     Search Project    ${PROJECT.TENDER_ID}
#     # 3.User clicks data cleaning button.
#     Wait For Elements State    ${Project_toolbar_DataCleaningButton}    enabled    20
#     Click If Enabled    ${Project_toolbar_DataCleaningButton}
#     # 4.User clicks upload button.
#     Data Upload Template    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}    ${PROJECT.TEMPLATE}
#     # 5.User select location/Port routing.
#     IF    '${Select_By}' == 'Location'
#         ${Status}    Run Keyword And Return Status    Get Checkbox State    xpath=//input[@value='location']    ==    checked
#         IF    '${Status}' == 'False'
#             Click    xpath=//input[@value='location']
#         END
#     ELSE
#         ${Status}    Run Keyword And Return Status    Get Checkbox State    xpath=//input[@value='port']    ==    checked
#         IF    '${Status}' == 'False'
#             Click    xpath=//input[@value='port']
#         END
#     END

#     IF    '${PROJECT.MODE}' == 'AIR'
#         ${Row}    Set Variable    2
#         ${Col}    Set Variable    27
#         Check Mapping Columns Checkbox    ${PROJECT.MODE}
#         Air Select Location Routing    ${Select_By}
#     ELSE IF    '${PROJECT.MODE}' == 'FCL'
#         ${Row}    Set Variable    2
#         ${Col}    Set Variable    29
#         Check Mapping Columns Checkbox
#         FCL Select Location Routing    ${Select_By}
#     ELSE
#         ${Row}    Set Variable    2
#         ${Col}    Set Variable    26
#         Check Mapping Columns Checkbox    LCL
#         LCL Select Location Routing    ${Select_By}
#     END
#     # 6.User clicks start button.
#     Click    ${Data_toolbar_StartButton}
#     Wait For Elements State    ${Summary_Succ}    visible    
#     Wait For Elements State   ${Data_toolbar_DownloadButton}     enabled
#     Get Element State    ${Data_toolbar_UploadAfterStartButton}    disabled    should not be    True
#     Get Element State    ${Data_toolbar_SetPassButton}    disabled    should not be    True
#     # 7.User clicks download button.
#     ${file_path}    Get Download ZIP File Name    ${PROJECT.TENDER_ID}    .zip
#     Should Contain    ${file_path}    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}
#     # 8.Modify the download file and user clicks upload button.
#     ${file_name2}    Modify ZIP Excel File    ${file_path}    ${Row}    ${Col}    ${PROJECT.MODE}    ${Modify_Value}
#     Data Upload Template After Modified    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}   ${file_name2}
#     Wait For Elements State   ${Data_toolbar_StartButton}     enabled
#     # 9.User click start button.
#     Click    ${Data_toolbar_StartButton}
#     Wait Until Keyword Succeeds    50    1    Get Page Source    contains        Please close this page and go to Generate Internal Pricing Template.
#     # 10.User click download button.
#     Wait Until Keyword Succeeds    50    1    Click    ${Data_toolbar_DownloadButton}
#     ${file_path}    Get Download ZIP File Name    ${PROJECT.TENDER_ID}    .zip
#     Check Modified Excel File    ${file_path}    ${Row}    ${Col}    ${PROJECT.MODE}    ${Modify_Value}
#     # 11.User clicks close button.
#     Click    ${Data_toolbar_CloseButton}
#     Wait For Elements State    ${Close_Warning_Text}    visible    
#     Click    ${YesCloseButton}

Data Cleaning
    [Arguments]    ${RoutingType}=Location    ${DataCleaningTemplateFile}=${PROJECT.TEMPLATE}
    # 1 User goes to Pricing Collaboration , Pricing Project.
    Wait Until Keyword Succeeds    5x    300ms    Click   ${navigation_pricing_project}
    Wait For Elements State    ${Project_toolbar_CreateButton}    visible    10
    Wait Until Search Finished
    # 2 User select the row which project name
    Search Project    ${PROJECT.TENDER_ID}   
    # 3 User clicks data cleaning button.
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_toolbar_DataCleaningButton}
    Wait Until Search Finished
    # 4.User clicks upload button.
    Wait For Elements State    ${Data_toolbar_UploadButton}    visible    10
    Wait For Elements State    ${Data_toolbar_UploadButton}    enabled    10
    Wait Until Keyword Succeeds    20x    100ms    Click    ${Data_toolbar_UploadButton}
    Wait For Elements State    ${Project_RoundMgmt_Confirm_UploadAddFile}    visible    10
    Upload File By Selector    ${upload_addFileButton}    ${DataCleaningTemplateFile}
    Wait Until Search Finished
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    300ms    Get Element States    ${upload_addFileButton}    not contains    visible
    Wait Until Keyword Succeeds    5x    300ms    Get Element States    ${Origin_Country}    contains    visible
    Wait Until Keyword Succeeds    5x    300ms    Get Element States    ${Origin_Country}    not contains    disabled
    # 5.User select location/Port routing.
    IF    '${RoutingType}' == 'Location'
            Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_DataClean_RoutingLocation}
    ELSE
            Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_DataClean_RoutingPort}
    END
    
    # select mapping value
    IF    '${PROJECT.MODE}' == 'AIR' 
        Air Select Location Routing    ${RoutingType}
    ELSE IF    '${PROJECT.MODE}' == 'FCL'  
        FCL Select Location Routing    ${RoutingType}
    ELSE
        LCL Select Location Routing    ${RoutingType}
    END
    # check checkbox
    Check Mapping Columns Checkbox    ${RoutingType}
    # Check Check Box for Routing

    # 6.User clicks start button.
    Wait Until Keyword Succeeds    5x    400ms    Click    ${Data_toolbar_StartButton}
    Wait Until Search Finished
    Wait For Elements State    ${Summary_Succ}    visible    60
    Wait For Elements State    ${Data_toolbar_DownloadButton}    enabled    60
    Wait Until Keyword Succeeds    5x    400ms    Get Element States    ${Data_toolbar_UploadAfterStartButton}    not contains    disabled
    Wait Until Keyword Succeeds    5x    400ms    Get Element States    ${Data_toolbar_SetPassButton}    not contains    disabled

    Wait Until Keyword Succeeds    5x    400ms    Click    ${Data_toolbar_CloseButton}
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    300ms    Wait For Elements State    ${Close_Warning_Text}    visible    
    Wait Until Keyword Succeeds    5x    300ms    Click    ${YesCloseButton}

Modify and Check Data Cleaning
    [Documentation]    AIR: ROW=2 Col=27 Modify_Value=1  FCL: ROW=2 Col=29 Modify_Value=1  LCL: ROW=2 Col=26 Modify_Value=1
    ${Modify_Value}    Set Variable    1
    IF    '${PROJECT.MODE}' == 'AIR' 
        ${Row}    Set Variable    2
        ${Col}    Set Variable    27
    END
    IF    '${PROJECT.MODE}' == 'FCL' 
        ${Row}    Set Variable    2
        ${Col}    Set Variable    29
    END
    IF    '${PROJECT.MODE}' == 'LCL' 
        ${Row}    Set Variable    2
        ${Col}    Set Variable    26
    END
    # 1 User goes to Pricing Collaboration , Pricing Project.
    Wait Until Keyword Succeeds    5x    300ms    Click   ${navigation_pricing_project}
    Wait For Elements State    ${Project_toolbar_CreateButton}    visible    10
    Wait Until Search Finished
    # 2 User select the row which project name
    Search Project    ${PROJECT.TENDER_ID}    
    # 3 User clicks data cleaning button.
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_toolbar_DataCleaningButton}
    Wait Until Search Finished
    Wait For Elements State    ${Data_toolbar_UploadButton}    visible    30
    Wait For Elements State    ${Data_toolbar_UploadButton}    enabled    30
    # 7.User clicks download button.
    ${zipFile}    Get Download ZIP File Name    ${PROJECT.TENDER_ID}    .zip
    Should Contain    ${zipFile}    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}
    # 8.Modify the download file and user clicks upload button.
    ${excelFile}    Modify ZIP Excel File    ${zipFile}    ${Row}    ${Col}    ${PROJECT.MODE}    ${Modify_Value}
    Data Upload Template After Modified    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}   ${excelFile}
    Wait For Elements State   ${Data_toolbar_StartButton}     enabled
    # 9.User click start button.
    Click    ${Data_toolbar_StartButton}
    Wait Until Keyword Succeeds    50    1    Get Page Source    contains        Please close this page and go to Generate Internal Pricing Template.
    # 10.User click download button.
    Remove All Files
    ${zipFile}    Get Download ZIP File Name    ${PROJECT.TENDER_ID}    .zip
    Check Modified Excel File    ${zipFile}    ${Row}    ${Col}    ${PROJECT.MODE}    ${Modify_Value}
    # 11.User clicks close button.
    Click    ${Data_toolbar_CloseButton}
    Wait For Elements State    ${Close_Warning_Text}    visible    
    Click    ${YesCloseButton}


Assign User_Project Owner
    [Arguments]    ${area:user}=None
    IF    '${area:user}'=='None'
            ${area:user}    Create List    
            ...    ${Project_RoundMgmt_Assign_ApacTab},xpath= //div[@data-model='availableItems']//ul//li//b[.='Mary Ma (MARYMA01)']
            ...    ${Project_RoundMgmt_Assign_EuropeTab},xpath= //div[@class='tab-pane ng-scope active']//div[@class='tab-pane ng-scope active']//b[.='Kiki Xia (KIKIXIA1)']
            ...    ${Project_RoundMgmt_Assign_NamTab},xpath = //b[.='Snow Li (SNOWLI01)']
    END
    Search Project    ${PROJECT.TENDER_ID}
    Wait Until Search Finished
    Click    ${Project_toolbar_RoundMgmtButton}
    Wait For Elements State    ${Project_RoundMgmt_CurrentRole}    enabled    60
    Wait Until Keyword Succeeds    20x    100ms    Select Options By   ${Project_RoundMgmt_CurrentRole}    label    Project Owner
    Wait Until Keyword Succeeds    20x    100ms    Click    ${Project_RoundMgmt_AssignButton}   
    ${areLength}    Get Length    ${area:user}
    FOR    ${element}    IN    @{area:user}
        ${tabString}    Split String    ${element}    ,
        Round Mgmt Assign User    ${tabString}[0]    ${tabString}[1]
    END 
    Click    ${Project_RoundMgmt_Assign_SaveButton}
    Wait Until Search Finished
    #     User clicks start button
    Click    ${Project_RoundMgmt_StartButton}
    #     User clicks yes button.
    Wait Until Keyword Succeeds    10x    100ms    Click    ${Project_RoundMgmt_StartConfirmButton} 
    Wait Until Search Finished
    #     User clicks send button.
    Wait Until Keyword Succeeds    20x    100ms    Click    ${Project_RoundMgmt_Confirm_SendButton}
    Wait Until Search Finished
    #     User clicks upload button and upload a file.
    #  Expected:
    #     The file can upload successfully and show the file information
    #     in detail, document name, upload by,date &time, authority.
    Wait Until Keyword Succeeds    10x    500ms    Click    ${Project_RoundMgmt_Attach_UploadButton}
    Wait For Elements State    ${upload_addFileButton}    enabled    30
    Wait Until Keyword Succeeds    10x    500ms    Upload File By Selector    ${upload_addFileButton}    ${PROJECT.TEMPLATE}
    Wait Until Keyword Succeeds    10x    500ms    Get Element States    ${upload_addFileButton}    not contains    visible
    ${filePathList}    Split String     ${PROJECT.TEMPLATE}    ${/}
    ${fileName}    Get From List    ${filePathList}    -1
    ${curDate}    Get Current Date    result_format=%d/%m/%Y
    Sleep    3
    Wait Until Keyword Succeeds    10x    500ms    Get Element States    xpath=//tr[td//text()[contains(.,"${fileName}")]][td//text()[contains(.,"${USERNAME_FULL}")]]    contains    visible
    Wait Until Keyword Succeeds    10x    500ms    Get Element States    xpath=//tr[td//text()[contains(.,"${curDate}")]][td//text()[contains(.,"APAC,EUROPE,NAM")]]    contains    visible
    #     User clicks close button.
    Click    ${Project_RoundMgmt_CloseButton}
    Close Browser

Assign User_Regional Pricing
    [Arguments]    ${curUser}    ${currentRole}    ${county:user}    ${cluster:user}
    Set Global Variable    ${USERNAME}    ${curUser}
    Login Space
    Search Project    ${PROJECT.TENDER_ID}
    Wait Until Search Finished
    ${noneExists}    Set Variable    FALSE
    Click    ${Project_toolbar_RoundMgmtButton}
    Wait For Elements State    ${Project_RoundMgmt_CurrentRole}    enabled    60
    Wait Until Keyword Succeeds    20x    300ms    Select Options By   ${Project_RoundMgmt_CurrentRole}    label    ${currentRole}
    # User MARYMA01 clicks download button in generation information
    # Click    ${Project_RoundMgmt_Attach_DownloadButton}
    # Click    ${Project_RoundMgmt_DownloadIPTButton}
    # ${fileName}    Get Download File Name    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}_Round1_IPT
    # Remove File    ${fileName} 

    #     User MARYMA01 checks value of the download file
    # Click    ${Project_RoundMgmt_Attach_DownloadButton}
    ###not necessary to check every cell value
    #     User MARYMA01 clicks assignment image and selects candidates according to the below picture
    Wait Until Keyword Succeeds    20x    300ms    Click    ${Project_RoundMgmt_AssignButton}

    ## IF country tab is not exists then click Trade Lane Reefer
    Run Keyword And Ignore Error     Click    xpath = //form[@name='assignmentForm']//a[.='Trade Lane Reefer']
    Run Keyword And Ignore Error     Click    xpath = //form[@name='assignmentForm']//a[.='Country']
    ##
    ##assign country user
    ${areLength}    Get Length    ${county:user}
    FOR    ${element}    IN    @{county:user}
        ${tabString}    Split String    ${element}    ,
        IF    "${tabString}[1]"=="None"
            ${noneExists}    Set Variable    TRUE
            Wait Until Keyword Succeeds    20x    300ms   Click    xpath = //a[.='${tabString}[0]']
            Click if Enabled     ${Project_RoundMgmt_Assign_RemoveAll}
        ELSE    
            Round Mgmt Assign User    xpath = //a[.='${tabString}[0]']    xpath = //form[@name='assignmentForm']//div[@class='tab-pane ng-scope active']//div[@class='tab-pane ng-scope active']//b[.='${tabString}[1]']
        END    
    END 
    Run Keyword And Ignore Error     Click    xpath = //form[@name='assignmentForm']//a[.='Cluster']
    FOR    ${element}    IN     @{cluster:user}
        ${tabString}    Split String    ${element}    ,
        IF    "${tabString}[1]"=="None"
            ${noneExists}    Set Variable    TRUE
            Wait Until Keyword Succeeds    20x    300ms   Click    xpath = //a[.='${tabString}[0]']
            Click if Enabled     ${Project_RoundMgmt_Assign_RemoveAll}
        ELSE    
            Round Mgmt Assign User    xpath = //a[.='${tabString}[0]']    xpath = //form[@name='assignmentForm']//div[@class='tab-pane ng-scope active']//div[@class='tab-pane ng-scope active']//b[.='${tabString}[1]']
        END    
    END
    Click    ${Project_RoundMgmt_Assign_SaveButton}
    IF     "${noneExists}"=="TRUE"
        Wait Until Keyword Succeeds    20x    300ms    Click    xpath = //span[.='Confirm']
    END 
    Wait Until Search Finished
    #     User MARYMA01 clicks send notification button
    Wait Until Keyword Succeeds    20x    300ms    Click    ${Project_RoundMgmt_SendNotifButton}
    #     User MARYMA01 clicks send button
    Wait Until Keyword Succeeds    20x    300ms    Click    ${Project_RoundMgmt_Confirm_SendButton}
    #     User MARYMA01 clicks close button
    Wait Until Keyword Succeeds    20x    300ms    Click    ${Project_RoundMgmt_CloseButton}
    Close Browser

SubmitPrice
    [Arguments]    ${user}     ${region}    ${submitCharges}    ${modifyCell}=None    ${defaultLanes}=5    ${segment}=ALL
    Remove All Files
    Close All Excel Documents
    Set Global Variable    ${USERNAME}    ${user}
    Login Space
    Search Project    ${PROJECT.TENDER_ID}
    #************************Step 1******************************
    #  Do:
    #     User MARYMA01 clicks round management button 
    #     and select my current role to 'Country Pricing Manager(CN-C)
    #  Expected:
    #     It can be selected successfully
    #************************************************************
    Log    ******************Step 1******************************
    Click    ${Project_toolbar_RoundMgmtButton}
    Wait For Elements State    ${Project_RoundMgmt_CurrentRole}    enabled    60
    Wait Until Keyword Succeeds    20x    300ms    Select Options By   ${Project_RoundMgmt_CurrentRole}    label    ${region}

    #************************Step 2******************************
    #  Do:
    #     User MARYMA01 download button
    #  Expected:
    #     The file can be downloaded successfully
    #************************************************************
    Log    ******************Step 2******************************
    ${filename}    Download File    ${Project_RoundMgmt_DownloadIPTButton}

    #************************Step 3******************************
    #  Do:
    #     User MARYMA01 opens the downloaded file
    #  Expected:
    #     1.There is one lane.
    #     2.The value of the lane is the same as project owner uploaded
    #************************************************************
    Log    ******************Step 3******************************
    # ${filename}    Get Download File Name    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}_Round1
    Sleep    2
    Open Excel Document     ${filename}    ${PROJECT.MODE}_D
    ${landInfo}    Read Excel Column    1
    ${rowCount}    Get Length    ${landInfo}
    Should Be Equal As Integers    ${rowCount}    ${defaultLanes}   ##there are five rows incldued column title
   
    #************************Step 4******************************
    #  Do:
    #     User MARYMA01 modifies the download file and save the file
    #  Expected:
    #     It can be modified successfully
    #************************************************************
    Log    ******************Step 4******************************
    ${status}    Run Keyword And Return Status    Should Be Equal As Strings     ${modifyCell}    None
    IF    '${status}'=='False'
          ${modifyInfo}    Split String    ${modifyCell}    ;
          ${rowNum}    Set Variable    ${modifyInfo}[0]
          ${columnTitle}    Set Variable    ${modifyInfo}[1]
          ${columnValue}    Set Variable    ${modifyInfo}[2]
          ${INDEX}    Get Excel Column Index    ${columnTitle}     ${rowNum}
          ${rowNum}    Evaluate    ${rowNum}+1
          Write Excel Cell     5    ${INDEX}     ${columnValue}    ${PROJECT.MODE}_D
          Save Excel Document    ${filename}
    END
    Close Current Excel Document
    Sleep    2

    #************************Step 5******************************
    #  Do:
    #     User MARYMA01 clicks submission button
    #  Expected:
    #     1.A dialogue named submission lanes appears.
    #     2.There three parts in this dialogue:   
    #       Step 1: Select Segments,  
    #       Step2: Upload Charges, Step 3: Submit Charges.
    #************************************************************
    Log    ******************Step 5******************************
    Click    ${Project_RoundMgmt_SubmissionButton}

    #************************Step 6******************************
    #  Do:
    #     User MARYMA01 clicks select all.
    #  Expected:
    #     All of the options are checked
    #************************************************************
    Log    ******************Step 6******************************
    Wait Until Keyword Succeeds    10x    400ms    Get Element States    ${Project_RoundMgmt_Submit_SelectAll}    not contains    disabled
    Sleep    1
    Wait Until Keyword Succeeds    10x    400ms    Click     ${Project_RoundMgmt_Submit_SelectAll}
    IF    "${PROJECT.MODE}"=="AIR"
        Check Text Value    css = [data-ng-model='submission.originCharge']    on
        Check Text Value    css = [data-ng-model='submission.destinationCharge']    on
        Check Text Value    css = [data-ng-model='submission.airfreightCharge']    on
        Check Text Value    css = [data-ng-model='submission.airfreightCharge']    on
        Check Text Value    css = [data-ng-model='submission.destinationLinehaul']    on

    ELSE IF   "${PROJECT.MODE}"=="FCL"
         Check Text Value    css = [data-ng-model='submission.preCarriageChargeFcl']    on
         Check Text Value    css = [data-ng-model='submission.carriageChargeFcl']    on
         Check Text Value    css = [data-ng-model='submission.originLocalChargesFcl']    on
         Check Text Value    css = [data-ng-model='submission.destinationLocalChargesFcl']    on
         Check Text Value    css = [data-ng-model='submission.carrierRatedOriginChargesFcl']    on
         Check Text Value    css = [data-ng-model='submission.carrierRatedDestinationChargesFcl']    on
         Check Text Value    css = [data-ng-model='submission.oceanTransportChargeFcl']    on
    ELSE     
         Check Text Value    css = [data-ng-model='submission.originChargeLcl']    on
         Check Text Value    css = [data-ng-model='submission.oceanFreightChargeLcl']    on
         Check Text Value    css = [data-ng-model='submission.destinationChargesLcl']    on
    END
    ${status}    Run Keyword And Return Status    Should Be Equal As Strings    ${segment}    ALL
    IF    "${status}"!="True"
         FOR    ${element}    IN     @{segment}
               Click    ${element}
         END    
    END
    #************************Step 7******************************
    #  Do:
    #     User MARYMA01 clicks upload button and uploads the modified file
    #  Expected:
    #     It can upload successfully.
    #     A prompt comes up, 'Summary: SUCCESSFUL Your selected lanes have been uploaded!'
    #     There is submit button
    #************************************************************
    Log    ******************Step 7******************************
    Click    ${Project_RoundMgmt_Submit_UploadButton}
    Wait For Elements State    ${Project_RoundMgmt_Confirm_UploadAddFile}    visible    10
    Wait Until Keyword Succeeds    10x    400ms    Upload File By Selector    ${upload_addFileButton}    ${filename}
    Wait Until Search Finished
    Wait Until Search Finished
    Wait Until Keyword Succeeds    10x    1s    Get Text    css = [data-ng-if='submission.success']    contains    Summary: SUCCESSFUL
    Get Text    css = [data-ng-if='submission.success']    contains    Your selected lanes have been uploaded!
    Remove All Files

    #************************Step 8******************************
    #  Do:
    #     User MARYMA01 clicks submit button
    #  Expected:
    #      A prompt comes up, 'Summary: SUCCESSFUL
    #     Your rates have been submitted!
    #************************************************************
    Log    ******************Step 8******************************
    Click    ${Project_RoundMgmt_Submit_SubmitButton}
    Wait Until Keyword Succeeds    10x    400ms    Get Page Source    contains        Your rates have been submitted!
    #************************Step 9******************************
    #  Do:
    #     User MARYMA01 clicks close button
    #  Expected:
    #      The dialogue disappears
    #************************************************************
    Log    ******************Step 9******************************
    Click    ${Project_RoundMgmt_Submit_CloseButton}
    
    #************************Step 10******************************
    #  Do:
    #     User MARYMA01 clicks download button
    #  Expected:
    #      1.A file can download successfully.
    #     2.Check the modified column values. The values are equal to modified.
    #     3.Submission button is disappeared
    #************************************************************
    Log    ******************Step 10******************************
    ${filename}    Download File    ${Project_RoundMgmt_DownloadIPTButton}
    # ${filename}    Get Download File Name    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}_Round1
    Open Excel Document     ${filename}    ${PROJECT.MODE}_D
    ${status}    Run Keyword And Return Status    Should Be Equal As Strings     ${modifyCell}    None
    IF    '${status}'=='False'
          ${modifyInfo}    Split String    ${modifyCell}    ;
          ${rowNum}    Set Variable    ${modifyInfo}[0]
          ${columnTitle}    Set Variable    ${modifyInfo}[1]
          ${columnValue}    Set Variable    ${modifyInfo}[2]
          ${INDEX}    Get Excel Column Index    ${columnTitle}     ${rowNum}
          ${rowNum}    Evaluate    ${rowNum}+1
          Check Cell Value    5    ${INDEX}     ${columnValue}    ${PROJECT.MODE}_D
    END
    Close Current Excel Document
    Get Element States    ${Project_RoundMgmt_SubmissionButton}    not contains    visible

    #************************Step 11******************************
    #  Do:
    #     User MARYMA01 clicks my tasks tab
    #  Expected:
    #      1.The task named submit charges for country [CN-C](1 Lanes) is completed.
    #     2.Check other country/cluster status if it is right to actual condition
    #************************************************************
    Log    ******************Step 11******************************
    Sleep    2
    Wait Until Keyword Succeeds    20x    100ms    Click    ${Project_RoundMgmt_CloseButton}
    Wait Until Keyword Succeeds    3x    500ms    Search Project    ${PROJECT.TENDER_ID}
    Click    ${Project_toolbar_RoundMgmtButton}
    Wait Until Keyword Succeeds    20x    100ms    Select Options By   ${Project_RoundMgmt_CurrentRole}    label    ${region}
    Wait Until Search Finished 
    Wait Until Keyword Succeeds    10x    400ms    Click    xpath = //a[.='My Tasks']
    ${lane}    Set Variable    [td//text()[contains(.,"${submitCharges}")]]
    ${status}    Set Variable    [td//text()[contains(.,"Completed")]]
    Wait Until Keyword Succeeds    10x    400ms    Get Element States     xpath = //tr${lane}${status}    contains    visible
    Wait Until Keyword Succeeds    10x    400ms    Click    ${Project_RoundMgmt_CloseButton}
    Close Browser

Close Round
    ##After all the pricing submission, project owner logs in and downloads the internal pricing template.
    Set Global Variable    ${USERNAME}     AUTOTEST
    Login Space
    Search Project    ${PROJECT.TENDER_ID}
    Click    ${Project_toolbar_RoundMgmtButton}
    Wait For Elements State    ${Project_RoundMgmt_CloseRoundButton}    enabled    60
    #User clicks close round button.
    Wait Until Keyword Succeeds    20x    100ms    Click    ${Project_RoundMgmt_CloseRoundButton}
    # 1.A dialogue named 'close round**' appears.
    # 2. The default status of the checkbox is checked.  
    # Wait Until Keyword Succeeds    20x    100ms    Check Text Value    xpath = //input[@name='sendChk']    on
    # User clicks yes button.
    Click    //button[contains(., "Yes")]
    #1.A prompt says 'Close Success'.
    # 2.Current Pricing Round: 1 (Closed) 2 lanes
    # 3.There have new round button and reopen round button.
    Wait Until Keyword Succeeds    20x    100ms    Get Page Source    contains    Close Success
    Get Element States    ${Project_RoundMgmt_NewRoundButton}    contains    visible
    Get Element States    ${Project_RoundMgmt_ReopenRoundButton}    contains    visible
    Click    css=[data-ng-click="closeRoundPage()"]
    
Copy Data
    [Arguments]    ${SourceTenderID}    ${SourceTenderMode}    ${SourceTenderName}
    Click    ${Project_toolbar_CopyData}
    Wait Until Search Finished
    get element states    ${Project_CopyData_Mode}    contains    disabled
    Get Text    ${Project_CopyData_Customer Name}    ==    ${EMPTY}
    Get element states    ${Project_CopyData_TenderID}    contains    enabled
    Get element states    ${Project_CopyData_TenderLead}    contains    enabled
    Get element states    ${Project_CopyData_RFQLaunchDate}    contains    enabled
    Get element states    ${Project_CopyData_SearchButton}    contains    enabled
    Get element states    ${Project_CopyData_CopyDataButton}    contains    disabled
    Get element states    ${Project_CopyData_Noentrypresent}    contains    visible
    Fill Text    ${Project_CopyData_TenderID}    ${SourceTenderID}
    Click    ${Project_CopyData_SearchButton}
    Wait Until Search Finished
    Get element states    (//h4[contains(text(),"Copy Target Project")]/../..//tr)[2]    contains    visible
    Click    (//h4[contains(text(),"Copy Target Project")]/../..//tr)[2]//td[1]
    Click    ${Project_CopyData_CopyDataButton}
    Click    ${Dialog_yesButton}
    Wait Until Search Finished
    ${Message}    Browser.Get Text    (//h4[contains(text(),"Congratulations")]/../..//span)[1]
    Should Contain    ${Message}    Tender has been successfully copied from [${SourceTenderID}-${SourceTenderMode}-${SourceTenderName}].
    Should Contain    ${Message}    Please adjust the template and the lanes in Template / Lane Management page if required.
    Wait Until Search Finished
    Click    ${CongratulationsDialog_OKButton}
    Wait Until Search Finished
    Get element states    //span[contains(text(),"Tender has been successfully copied from [${SourceTenderID}-${SourceTenderMode}-${SourceTenderName}]. Please adjust the template and the lanes in Template / Lane Management page if required.")]    contains    visible

Click Next Round Management Dialog And Check 
    Click    ${Template_gotoNextButton}
    Wait Until Search Finished
    Get Element States    //span[contains(.,'Project ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE} Round1')]    contains    visible
    Get Element States    //legend[.="Generation Information"]    contains    visible
    Get Element States    //span[contains(.,'1 (Not Started) 2 lanes')] /../b[contains(.,'Current Pricing Round')]    contains    visible
    Get Element States    //span[contains(.,'1 (Not Started) 2 lanes')]    contains    visible
    Get Element States    //legend[.="Assignment"]    contains    visible
    Get Element States    //legend[.="Attached Document"]    contains    visible
    Get Element States    //legend[.="Round History"]    contains    visible
    Get Element States    //a[.="Region"]    contains    visible
    Get Element States    //a[.="My Tasks"]    contains    visible

Assign My Current Role
    [Arguments]    ${Role}
    Wait For Elements State    ${Project_RoundMgmt_CurrentRole}    enabled    60
    Click    ${Project_RoundMgmt_CurrentRole}
    Click    //div[contains(text(),"${Role}")]

Click DataClean For Delete
    Search Project    ${G_TENDERID}
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_toolbar_DataCleaningButton}
    Click    //button[contains(., "Yes")]
    Wait For Elements State    ${Data_toolbar_UploadButton}    visible    30
    Click    ${Data_toolbar_CloseButton}
    Click    //button[contains(., "Yes")]
    Wait Until Search Finished

Input Deadline In Country Tab
    [Arguments]    ${row}=0    ${col}=0    ${Date}=default
    ${CurDate}    Get Current Date    result_format=%d/%m/%Y
    IF    '${Date}'!='default'
        Fill Text    //input[@id='rcountry_Date_${row}_${col}']    ${Date}
        Wait Until Search Finished
    ELSE
        Fill Text    //input[@id='rcountry_Date_${row}_${col}']    ${CurDate}
        Wait Until Search Finished
    END

Input Deadline In Cluster Tab
    [Arguments]    ${row}=0    ${col}=0    ${Date}=default
    ${CurDate}    Get Current Date    result_format=%d/%m/%Y
    IF    '${Date}'!='default'
        Fill Text    //input[@id='clusterAssignmet_Date_${row}_${col}']    ${Date}
        Wait Until Search Finished
    ELSE
        Fill Text    //input[@id='clusterAssignmet_Date_${row}_${col}']    ${CurDate}
        Wait Until Search Finished
    END

Input Deadline In Region Tab
    [Arguments]    ${row}=0    ${col}=0    ${Date}=default
    ${CurDate}    Get Current Date    result_format=%d/%m/%Y
    IF    '${Date}'!='default'
        Fill Text    //input[@id='regionAssignmet_Date_${row}_${col}']    ${Date}
        Wait Until Search Finished
    ELSE
        Fill Text    //input[@id='regionAssignmet_Date_${row}_${col}']    ${CurDate}
        Wait Until Search Finished
    END

Input Deadline In TradeLaneStandard Tab
    [Arguments]    ${row}=0    ${col}=0    ${Date}=default
    ${CurDate}    Get Current Date    result_format=%d/%m/%Y
    IF    '${Date}'!='default'
        Fill Text    //input[@id='trade_Date_${row}_${col}']    ${Date}
        Wait Until Search Finished
    ELSE
        Fill Text    //input[@id='trade_Date_${row}_${col}']    ${CurDate}
        Wait Until Search Finished
    END